/********************************************************************
	created:	2012/04/07   23:27
	filename: 	hy_queue.h
	author:		supercaco@sina.com
	purpose:	
*********************************************************************/
#ifndef _HY_QUEUE_H_
#define _HY_QUEUE_H_

#include "hy_mutex.h"
#include "hy_scope_locker.h"

template<typename DataType>
class hy_queue
{
public:
	typedef DataType	data_block_t;
	typedef DataType*	iterator;
public:
	hy_queue (bool Locked = true):mutex_(Locked)
	{

	}
	~hy_queue ()
	{

	}

	bool empty()
	{
		hy_lock lock(mutex_);
		return deque_.empty();
	}

	data_block_t* pop_front()
	{
		data_block_t* data = NULL;
		hy_lock lock(mutex_);
		if (!deque_.empty())
		{
			data = deque_.front();
			deque_.pop_front();
		}
		return data;
	}

	data_block_t* front()
	{
		data_block_t* data = NULL;
		hy_lock lock(mutex_);
		if (!deque_.empty())
		{
			data = deque_.front();
		}
		return data;
	}

	void push_back(data_block_t* data)
	{
		hy_lock lock(mutex_);
		deque_.push_back(data);
	}

	void swap(hy_queue& que)
	{
		hy_lock lock(mutex_);
		deque_.swap(que.deque_);
	}
	void clear()
	{
		hy_lock lock(mutex_);
		deque_.clear();
	}

private:
	hy_fast_mutex				mutex_;
	deque<data_block_t*>		deque_;
};

#endif  //_HY_QUEUE_H_
